syntax = "proto3";

package kuma.mesh.v1alpha1;

option go_package = "github.com/kumahq/kuma/api/mesh/v1alpha1";

import "api/mesh/options.proto";
import "api/mesh/v1alpha1/envoy_admin.proto";
import "kuma-doc/config.proto";

option (doc.config) = {
  type : Proxy,
  name : "ZoneIngress",
  file_name : "zoneingress"
};

// ZoneIngress allows us to configure dataplane in the Ingress mode. In this
// mode, dataplane has only inbound interfaces. Every inbound interface matches
// with services that reside in that cluster.
message ZoneIngress {

  option (kuma.mesh.resource).name = "ZoneIngressResource";
  option (kuma.mesh.resource).type = "ZoneIngress";
  option (kuma.mesh.resource).global = true;
  option (kuma.mesh.resource).package = "mesh";
  option (kuma.mesh.resource).kds.send_to_global = true;
  option (kuma.mesh.resource).kds.send_to_zone = true;
  option (kuma.mesh.resource).ws.name = "zone-ingress";
  option (kuma.mesh.resource).ws.plural = "zone-ingresses";
  option (kuma.mesh.resource).scope_namespace = true;
  option (kuma.mesh.resource).has_insights = true;
  option (kuma.mesh.resource).additional_printer_columns =
      "description=\"Zone name\""
      ",JSONPath=`.spec.zone`"
      ",name=\"zone\",type=string";

  // Zone field contains Zone name where ingress is serving, field will be
  // automatically set by Global Kuma CP
  string zone = 1;

  message Networking {
    // Address on which inbound listener will be exposed
    string address = 1 [ (doc.required) = true ];

    // AdvertisedAddress defines IP or DNS name on which ZoneIngress is
    // accessible to other Kuma clusters.
    string advertisedAddress = 2 [ (doc.required) = true ];

    // Port of the inbound interface that will forward requests to the service.
    uint32 port = 3 [ (doc.required) = true ];

    // AdvertisedPort defines port on which ZoneIngress is accessible to other
    // Kuma clusters.
    uint32 advertisedPort = 4 [ (doc.required) = true ];

    // Admin contains configuration related to Envoy Admin API
    EnvoyAdmin admin = 5;
  }

  // Networking defines the address and port of the Ingress to listen on.
  // Additionally publicly advertised address and port could be specified.
  Networking networking = 2 [ (doc.required) = true ];

  message AvailableService {
    // tags of the service
    map<string, string> tags = 1;
    // number of instances available for given tags
    uint32 instances = 2;
    // mesh of the instances available for given tags
    string mesh = 3;
    // instance of external service available from the zone
    bool externalService = 4;
  }

  // AvailableService contains tags that represent unique subset of
  // endpoints
  repeated AvailableService availableServices = 3;
}
